<template>
	<view class="blindList">
		<view class="" style="position: fixed;top: 0;left: 0;width: 750rpx;z-index: 99999;" v-if="ceShow">
			<u-notice-bar mode="horizontal" :list="noticeList"></u-notice-bar>
		</view>
		<view class="blindListItem" v-for="(item,index) in list" :key="index" @click="chooseItem(item)">
			<image :src="item.image" mode=""></image>
			<view class="blindListItemTitle">
				{{item.title}}
			</view>
			<view class="blindListItemInfo">
				<view class="blindListItem_time">
					{{timestamp(item.createtime)}} 发布
				</view>
				<view class="blindListItem_num">
					{{item.pv}} 浏览量
				</view>
			</view>
		</view>
		<view class="" style="padding: 20rpx 0;">
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex';
	import {
		baseUrl
	} from '@/config/config.js'
	import {
		getXqList
	} from '@/api/index.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				baseUrl: '',
				page: 1,
				limit: 10,
				list: [],
				ceShow: false,
				noticeList: []
			}
		},
		onReachBottom() {
			if(this.status == 'nomore')return
			this.page++
			this.getList()
		},
		watch: {
			socketMessage(newVal, oldVal) {
				if (newVal) {
					this.ceShow = true
					this.noticeList = [newVal.slice(0,-1)]
					setTimeout(() => {
						this.ceShow = false
					}, 10000)
				}
			}
		},
		computed: {
			...mapGetters(['getSocketMessage']),
			socketMessage() {
				return this.getSocketMessage;
			}
		},
		methods: {
			chooseItem(item){
				uni.navigateTo({
					url:`/pages/views/blindDetail?id=${item.id}`
				})
			},
			async getList() {
				this.status = 'loading'
				const res = await getXqList({
					page: this.page,
					limit: this.limit
				})
				this.list = [...this.list, ...res.data.data]
				if(res.data.data.length<this.limit){
					this.status = 'nomore'
				}else{
					this.status = 'loadmore'
				}
			},
			timestamp(timestamp) {
				var date = new Date(timestamp * 1000); // 转换为毫秒
				var year = date.getFullYear();
				var month = ('0' + (date.getMonth() + 1)).slice(-2);
				var day = ('0' + date.getDate()).slice(-2);
				var hours = ('0' + date.getHours()).slice(-2);
				var minutes = ('0' + date.getMinutes()).slice(-2);
				var seconds = ('0' + date.getSeconds()).slice(-2);

				return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
			}
		},
		onLoad() {
			this.ws.pageFun(this.pageDataLoad, this);
			this.baseUrl = baseUrl
			this.getList()
		}
	}
</script>

<style scoped lang="scss">
	.blindList {
		min-height: 100vh;
		background-color: #fff;
		padding: 0 60rpx;

		.blindListItem {
			padding: 20rpx 0;

			image {
				width: 100%;
				height: 354rpx;
			}

			.blindListItemTitle {
				margin-top: 10rpx;
				max-width: 630rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.blindListItemInfo {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 10rpx;
				font-size: 22rpx;
				color: #999;

				.blindListItem_time {}
			}
		}
	}
</style>